//
// File: fftshift.cpp
//
// MATLAB Coder version            : 4.0
// C/C++ source code generated on  : 18-Dec-2020 16:50:24
//

// Include Files
#include "rt_nonfinite.h"
#include "sea_parameter_cal.h"
#include "fftshift.h"

// Function Definitions

//
// Arguments    : creal_T x[4194304]
// Return Type  : void
//
void fftshift(creal_T x[4194304])
{
  int dim;
  int vlend2;
  static const short iv0[3] = { 256, 256, 64 };

  int vstride;
  int k;
  int npages;
  int vspread;
  int midoffset;
  int i2;
  int i;
  int i1;
  int j;
  int ia;
  int ib;
  double xtmp_re;
  double xtmp_im;
  int ic;
  for (dim = 0; dim < 3; dim++) {
    vlend2 = iv0[dim] / 2;
    vstride = 1;
    for (k = 1; k <= dim; k++) {
      vstride <<= 8;
    }

    npages = 1;
    for (k = dim + 1; k + 1 < 4; k++) {
      npages *= iv0[k];
    }

    vspread = (iv0[dim] - 1) * vstride;
    midoffset = vlend2 * vstride;
    if (vlend2 << 1 == iv0[dim]) {
      i2 = 0;
      for (i = 1; i <= npages; i++) {
        i1 = i2 - 1;
        i2 += vspread;
        for (j = 1; j <= vstride; j++) {
          i1++;
          i2++;
          ia = i1;
          ib = i1 + midoffset;
          for (k = 1; k <= vlend2; k++) {
            xtmp_re = x[ia].re;
            xtmp_im = x[ia].im;
            x[ia] = x[ib];
            x[ib].re = xtmp_re;
            x[ib].im = xtmp_im;
            ia += vstride;
            ib += vstride;
          }
        }
      }
    } else {
      i2 = 0;
      for (i = 1; i <= npages; i++) {
        i1 = i2 - 1;
        i2 += vspread;
        for (j = 1; j <= vstride; j++) {
          i1++;
          i2++;
          ia = i1;
          ib = i1 + midoffset;
          xtmp_re = x[ib].re;
          xtmp_im = x[ib].im;
          for (k = 1; k <= vlend2; k++) {
            ic = ib + vstride;
            x[ib] = x[ia];
            x[ia] = x[ic];
            ia += vstride;
            ib = ic;
          }

          x[ib].re = xtmp_re;
          x[ib].im = xtmp_im;
        }
      }
    }
  }
}

//
// File trailer for fftshift.cpp
//
// [EOF]
//
